import java.util.*;

/**
 * @author ghp
 * @title 最小覆盖子串
 */
class Solution {

    private Deque<Integer> path = new LinkedList<>();

    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> ans = new ArrayList<>();
        ans.add(Collections.emptyList());
        boolean[] vis = new boolean[nums.length];
        bfs(ans, path, vis, nums, 0);
        return ans;
    }

    private void bfs(List<List<Integer>> ans, Deque<Integer> path, boolean[] vis, int[] nums, int step) {
        if (path.size() > nums.length) {
            return;
        }
        for (int i = step; i < nums.length; i++) {
            if (!vis[i]) {
                path.addLast(nums[i]);
                vis[i] = true;
                ans.add(new ArrayList<>(path));
                bfs(ans, path, vis, nums,   i);
                vis[i] = false;
                path.removeLast();
            }
        }
    }
}